package com.koron.ticket.work.workteam.service;

import com.koron.common.core.util.CodeTools;
import com.koron.ticket.work.workteam.bean.WorkTeam;
import com.koron.ticket.work.workteam.bean.WorkTeamQuery;
import com.koron.ticket.work.workteam.mapper.WorkTeamMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkTeamService {
    public void insert(SessionFactory factory, WorkTeam workTeam) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        workTeamMapper.insert(workTeam);
    }

    public void batchInsertOnTicketId(SessionFactory factory, List<WorkTeam> list, String ticketId) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        list.stream().forEach(l->{
            l.setId(CodeTools.getCode32());
            l.setWorkTicketId(ticketId);
            l.setDeleteFlag(0);
        });
        workTeamMapper.batchInsert(list);
    }

    public void batchInsert(SessionFactory factory, List<WorkTeam> list) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        workTeamMapper.batchInsert(list);
    }

    public void deleteByWorkTicketId(SessionFactory factory, String workTicketId) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        workTeamMapper.deleteByWorkTicketId(workTicketId);
    }

    public List<WorkTeam> getList(SessionFactory factory, WorkTeamQuery workTeamQuery) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        List<WorkTeam> workTeamList = workTeamMapper.getList(workTeamQuery);
        return workTeamList;
    }

    public List<WorkTeam> queryById(SessionFactory factory, String workTicketId) {
        WorkTeamMapper workTeamMapper = factory.getMapper(WorkTeamMapper.class);
        List<WorkTeam> workTeamList = workTeamMapper.queryByWorkTicketId(workTicketId);
        return workTeamList;
    }
}
